﻿//========================================================
//
//  DESCRIPTION:  Cls_DS_NHOM_CHUCNANG.cs
//
//  CREATED:	HuyPVT, 07/02/2006
//
//  USED FOR:	Tạo mới, chỉnh sửa, xóa, liệt kê danh sách nhóm chức năng.
//
//=================================================

using System;
using System.Data;
using Microsoft.Practices.EnterpriseLibrary.Common;
using System.Data.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;

using QLNHK.BLL;

namespace QLNHK.BLL {
	//Name: Cls_DS_NHOM_CHUCNANG	Base class:	Cls_DS_NHOM_CHUCNANG
	//Author: 	Huypvt		Date: 07/02/2006
	//Modifier:	Khanhlq		Date: 08/02/2006
	/// <summary>
	/// Tạo mới, chỉnh sửa, xóa, liệt kê danh sách chức năng
	public class Cls_DS_NHOM_CHUCNANG
	{
		private const string ST_DS_NHOM_CHUCNANG_INSERT = "st_DS_NHOM_CHUCNANGInsert";
		private const string ST_DS_NHOM_CHUCNANG_UPDATE = "st_DS_NHOM_CHUCNANGUpdate";
		private const string ST_DS_NHOM_CHUCNANG_DELETE = "st_DS_NHOM_CHUCNANGDelete";
		private const string TABLE_NAME = "tb_DS_NHOM_CHUCNANG";
		private Database db;
		private int _iD_DS_Nhom_ChucNang;
		private string _ten;
		private bool _tinhTrang;
		public int ID_DS_Nhom_ChucNang
		{
			get{return this._iD_DS_Nhom_ChucNang;}
			set{this._iD_DS_Nhom_ChucNang = value;}
		}
		public string Ten
		{
			get{return this._ten;}
			set{this._ten = value;}
		}
		public bool TinhTrang
		{
			get{return this._tinhTrang;}
			set{this._tinhTrang = value;}
		}
		public Cls_DS_NHOM_CHUCNANG()
		{
			try
			{
				db = DatabaseFactory.CreateDatabase();
			}
			catch(Exception ex)
			{
				throw ex;
			}
		}

		public Cls_DS_NHOM_CHUCNANG(int id_ds_nhom_chucnang, string ten, bool tinhtrang)
		{
			this._iD_DS_Nhom_ChucNang = id_ds_nhom_chucnang;
			this._ten = ten;
			this._tinhTrang = tinhtrang;
		}
		/// Author: khanhlq . Date: 2/8/2006.
		/// Modifier: khanhlq. Date:  2/8/2006.
		/// Liệt kê những gì đã chỉnh sửa:
		/// <summary>
		/// Inserts the wrapper.
		/// </summary>
		/// <returns>dbCommand</returns>
		private DbCommand InsertWrapper()
		{
			DbCommand dbCommand = db.GetStoredProcCommand(Cls_DS_NHOM_CHUCNANG.ST_DS_NHOM_CHUCNANG_INSERT);
			db.AddInParameter(dbCommand,"@ID_DS_Nhom_ChucNang", DbType.Int32,"ID_DS_Nhom_ChucNang", DataRowVersion.Current);
			db.AddInParameter(dbCommand,"@Ten", DbType.String,"Ten", DataRowVersion.Current);
			db.AddInParameter(dbCommand,"@TinhTrang", DbType.Boolean,"TinhTrang", DataRowVersion.Current);
			return dbCommand;
		}
		/// Author: khanhlq . Date: 2/8/2006.
		/// Modifier: khanhlq. Date:  2/8/2006.
		/// Liệt kê những gì đã chỉnh sửa:
		/// <summary>
		/// Updates the wrapper.
		/// </summary>
		/// <returns>dbCommand</returns>
		private DbCommand UpdateWrapper()
		{
			DbCommand dbCommand = db.GetStoredProcCommand(Cls_DS_NHOM_CHUCNANG.ST_DS_NHOM_CHUCNANG_UPDATE);
			db.AddInParameter(dbCommand,"@ID_DS_Nhom_ChucNang", DbType.Int32, "ID_DS_Nhom_ChucNang", DataRowVersion.Current);
			db.AddInParameter(dbCommand,"@Ten", DbType.String, "Ten", DataRowVersion.Current);
			db.AddInParameter(dbCommand,"@TinhTrang", DbType.Boolean, "TinhTrang", DataRowVersion.Current);
			return dbCommand;
		}
		/// Author: khanhlq . Date: 2/8/2006.
		/// Modifier: khanhlq. Date:  2/8/2006.
		/// Liệt kê những gì đã chỉnh sửa:
		/// <summary>
		/// Deletes the wrapper.
		/// </summary>
		/// <returns>dbCommand</returns>
		private DbCommand DeleteWrapper()
		{
			DbCommand dbCommand = db.GetStoredProcCommand(Cls_DS_NHOM_CHUCNANG.ST_DS_NHOM_CHUCNANG_DELETE);
			return dbCommand;
		}
		/// Author: khanhlq . Date: 2/8/2006.
		/// Modifier: khanhlq. Date:  2/8/2006.
		/// Liệt kê những gì đã chỉnh sửa:
		/// <summary>
		/// Does the update.
		/// </summary>
		/// <param name="ds">ds : dataset đã thay đổi</param>
		/// <returns>result</returns>
		public int DoUpdate(DataSet ds)
		{
			try
			{
				int result = db.UpdateDataSet(ds,Cls_DS_NHOM_CHUCNANG.TABLE_NAME,this.InsertWrapper(),this.UpdateWrapper(),this.DeleteWrapper(),UpdateBehavior.Standard);
				return result;
			}
			catch(Exception ex)
			{
				throw ex;
			}
		}
	}

}
